﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using DevComponents.DotNetBar.Controls;

namespace WorkFlowSystem.Common
{
    public class CommonDefine
    {
        /// <summary>
        /// 清空容器中各控件缓存的值
        /// </summary>
        /// <param name="container">容器类控件</param>
        public static void clear_values(Control container)
        {

            for (int i = 0; i < container.Controls.Count; i++)
            {

                //如果是容器类控件 递归调用自己
                if (container.Controls[i].HasChildren)
                {
                    clear_values(container.Controls[i]);
                }
                else
                {
                    string name = container.Controls[i].GetType().Name;
                    switch (container.Controls[i].GetType().Name)
                    {
                        case "TextBox":
                            container.Controls[i].Text = "";
                            break;
                        case "RadioButton":
                            ((RadioButton)(container.Controls[i])).Checked = false;
                            break;
                        case "CheckBox":
                            ((CheckBox)(container.Controls[i])).Checked = false;
                            break;
                        case "ComboBox":
                            ((ComboBox)(container.Controls[i])).SelectedItem = null;
                            break;
                        case "TextBoxX":
                            container.Controls[i].Text = "";
                            break;
                        case "CheckBoxX":
                            ((CheckBoxX)(container.Controls[i])).Checked = false;
                            break;
                        case "ComboBoxX":
                            ((ComboBoxEx)(container.Controls[i])).SelectedItem = null;
                            break;
                        case "RichBoxX":
                            ((RichTextBoxEx)(container.Controls[i])).Text = "";
                            break;
                        default:
                            break;
                    }
                }
            }
        }

        /// <summary>
        /// 清空容器中各控件缓存的值
        /// </summary>
        /// <param name="container">容器类控件</param>
        public static void clear_values_dotnetbar(DevComponents.DotNetBar.BaseItem base_item)
        {
            for (int i = 0; i < base_item.Container.Components.Count; i++)
            {

                    switch (base_item.Container.Components[i].GetType().Name)
                    {
                        case "TextBoxX":
                            ((TextBoxX)(base_item.Container.Components[i])).Text = "";
                            break;
                        case "CheckBoxX":
                            ((CheckBoxX)(base_item.Container.Components[i])).Checked = false;
                            break;
                        case "ComboBoxX":
                            ((ComboBoxEx)(base_item.Container.Components[i])).SelectedItem = null;
                            break;
                        default:
                            break;
                    }
                
            }
        }

        public static bool validation_control(string target_str, string regex)
        {
            Regex reg = new Regex(regex);
            return reg.IsMatch(target_str);
        }

        public static string STATUS_NONE = "1";
        public static string STATUS_COMMIT = "2";
        public static string STATUS_DENY = "3";
        public static string STATUS_ADMIT = "4";
    }

    public class CurrentUser
    {
        public static int user_id;
        public static Authority user_auth;
        public static int user_did;
    }

    public enum Authority
    {
        USER = 1,
        MANAGER,
        BOSS,
        ADMIN,
        UNKNOW = -1
    }

    public enum LogLevel
    { 
        INFO = 1,
        WARN,
        ERROR
    }

    public enum TabTypes
    {
        RADIO = 1,      //单选项
        TARGET = 2,   //目标进度
        PROGRESS = 3,   //拖动条
        UNKNOW = -1
    }

    public enum RetCode
    {
        MSG_UNKNOWN = -1,
        
        MSG_CHGPSW_NOT_NULL = 100,
        MSG_CHGPSW_LENGTH_6_U,
        MSG_CHGPSW_TYPE,
        MSG_CHGPSW_OLD_ERROR,
        MSG_CHGPSW_NEW_OLD_ERROR,
        MSG_CHGPSW_UPDATE_SUCCESS,

        MSG_GROUP_NAME_LENGTH_20_D = 200,
        MSG_GROUP_UPDATE_SUCCESS,
        MSG_GROUP_ADD_SUCCESS
    }
}
